package com.gtenacg.cartoonservice.controller;


import com.gtenacg.cartoonservice.common.annotation.CheckToken;
import com.gtenacg.cartoonservice.common.Result;
import com.gtenacg.cartoonservice.pojo.model.RelationCartoonType;
import com.gtenacg.cartoonservice.service.RelationCartoonTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/relationCartoonType")
@RequiredArgsConstructor
@CheckToken
public class RelationCartoonTypeController {

    final RelationCartoonTypeService relationCartoonTypeService;

    @GetMapping("/list")
    public Result<List<RelationCartoonType>> list() {
        log.info("获取对应列表（漫画-类型）");
        List<RelationCartoonType> list = relationCartoonTypeService.list();
        return Result.success(list);
    }
    @GetMapping
    public Result<List<RelationCartoonType>> search(
            @RequestParam(required = false) Integer cid,
            @RequestParam(required = false) Integer ctid
    ) {
        log.info("获取对应列表（漫画-类型）, cid:{}, ctid:{}", cid, ctid);
        List<RelationCartoonType> list = relationCartoonTypeService.search(cid, ctid);
        return Result.success(list);
    }

    @PostMapping
    public Result<Integer> insert(@RequestBody RelationCartoonType relationCartoonType) {
        log.info("插入对应关系（漫画-类型）: {}", relationCartoonType);
        Integer id = null;
        id = relationCartoonTypeService.insert(relationCartoonType);
        return Result.success(id);
    }

    @PutMapping
    public Result<Void> update(@RequestBody RelationCartoonType relationCartoonType) {
        log.info("更新对应关系（漫画-类型）: {}", relationCartoonType);
        relationCartoonTypeService.update(relationCartoonType);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result<Void> delete(@PathVariable List<Integer> ids) {
        log.info("删除对应关系（漫画-类型）: {}", ids);
        relationCartoonTypeService.delete(ids);
        return Result.success();
    }
}
